$(function() {

	////////////////////////////////////////////////////////////////////////////////////////////////
	// init
	////////////////////////////////////////////////////////////////////////////////////////////////

		var __degrade6 = (jQuery.browser.msie && jQuery.browser.version <= 6);
		var __degrade7 = (jQuery.browser.msie && jQuery.browser.version <= 7);
		var __degrade8 = (jQuery.browser.msie && jQuery.browser.version <= 8);
		var __degrade9 = (jQuery.browser.msie && jQuery.browser.version <= 9);
		var __mobile = (navigator.userAgent.search(/(iOS|iPhone|iPad|Android)/) != -1);
		$('a.offsite').attr('target', '_blank');
		$('#cartsize').each(function() { var t = $(this), x, y; if ((x = $.getCookie('4t_scrc')) == null || (y = x.split('|')).length < 2) val = 0; else val = y[1]; t.text(' (' + val + ')'); });
		$.preloadImages('/site/images/xyzarrow1.png', '/site/images/xyzarrow2.png', '/site/images/livedemo-bar1bg.png', '/site/images/livedemo-bar2bg.png', '/site/images/livedemo-bar3bg.png');
		$('head').append('<script type="text/javascript" src="/site/init.curr.js"></script>');
		$.toRelativeTime('.tweets .when');

	////////////////////////////////////////////////////////////////////////////////////////////////
	// currency
	////////////////////////////////////////////////////////////////////////////////////////////////

		var currencyBoxOpener = $('#topmenu .currencyBoxOpener');

		if (currencyBoxOpener.exists())
		{
			var options = '', q = $.getCookie('4t_crcc');

			for (cc in ft_currencies)
				options = options + '<option value="' + cc + '"' + (q == cc ? ' selected="selected"' : '') + '>' + ft_currencies[cc][1] + '</option>';

			var currencyBox = $(
				'<div class="currencybox">' + 
					'<div class="panel">' +
						'<div class="inner">' +
							'<select name="currency">' +
								options +
							'</select>' +
							'<img src="/site/images/currency-info.png" alt="" />' +
							'<p>Hover over any money amount to see it in your selected currency. <strong>Note:</strong> These are only estimates based on recent exchange rates. All charges are in US dollars.</p>' +
						'</div>' +
					'</div>' +
				'</div>'
			);

			currencyBox
				.appendTo($('#main'))
				.css('position', 'absolute')
				.css('z-index', 1)
				.hide()
				.bind('hideBox', function() {
					currencyBox
						.fadeOut(100);
				})
				.bind('showBox', function() {
					currencyBox
						.css('left', '635px')
						.css('top', '90px')
						.fadeIn(200);
				})
				.bind('toggleBox', function() {
					if (currencyBox.visible())
						currencyBox.trigger('hideBox');
					else
						currencyBox.trigger('showBox');
				})
				.click(function(e) {
					e.stopPropagation();
				});

			currencyBox.find('select')
				.change(function() {
					var t = $(this), v = t.val();
					if (v == 'USD')
						$.removeCookie('4t_crcc');
					else
						$.setCookie('4t_crcc', v);
					af_reload();
				});

			currencyBoxOpener.click(function(e) {
				e.preventDefault();
				e.stopPropagation();
				currencyBox.trigger('toggleBox');
			});

			$('body').click(function(e) {
				currencyBox.trigger('hideBox');
			});
		}

		if ((q = $.getCookie('4t_crcc')) != null && q != 'USD' && ft_currencies[q])
		{
			$('span.money').each(function() {
				var t = $(this), v = "" + Math.round(parseFloat(ft_currencies[q][0]) * parseFloat(t.attr('title')) * 100 + 0.50000000001)/100, x = v.split('.');
				if (!x[1] || x[1].length < 2)
				{
					x[1] = ((x[1] ? x[1] : '') + '00').substring(0,2);
					v = x.join('.');
				}
				
				t.attr('title', q + ' ' + v + ' (approx)');
				t.css('border-bottom', 'dotted 1px').css('cursor', 'help');
			});
		}
		else
		{
			q = 'USD';
			$('span.money').attr('title', '');
		}

		$('#currencycode').text(' (' + q + ')');

	////////////////////////////////////////////////////////////////////////////////////////////////
	// dropdown
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_dropdown = function(mode) {
			var t = jQuery(this), pos = 0, optionsIndex = new Array(), options = new Array(), s = '', isLocked = false;
			var tmp = t.find('option'), n = 1, count = tmp.length;
			
			var dd, ddCurrentOption, ddList;

			t.hide();

			tmp.each(function() {
				var o = jQuery(this), ts = '';
				
				ts = 'option' + n;
				
				if (n == 1)
					ts = ts + ' first';
				else if (n == count)
					ts = ts + ' last';
				
				optionsIndex.push(o.val());
				options[o.val()] = o.text();
				s = s + '<li class="' + ts + '">' + o.text() + '</li>';
				
				n++;
			});
			
			if (t.prop('selectedIndex'))
				pos = t.prop('selectedIndex');

			// Create element
				switch (mode)
				{
					case 'wide':
					
						dd = jQuery(
							'<div class="dropdown_wide">' + 
								'<ul>' +
								s +
								'</ul>' +
							'</div>'
						);
						break;
				
					case 'default':
					default:
					
						dd = jQuery(
							'<div class="dropdown">' + 
								'<div class="currentOption"></div>' +
								'<ul>' +
								s +
								'</ul>' +
							'</div>'
						);
				}

			// Common stuff
				dd.insertAfter(t);

				dd
					.bind('switchNext', function() {
						if (isLocked)
							return;
						
						pos++;
						
						if (pos >= optionsIndex.length)
							pos = 0;
							
						dd.trigger('switchTo', pos);
					})
					.bind('switchPrev', function() {
						if (isLocked)
							return;

						pos--;
						
						if (pos < 0)
							pos = optionsIndex.length - 1;
							
						dd.trigger('switchTo', pos);
					})
					.bind('switchTo', function(e, n, noCallback) {
						if (isLocked)
							return;

						var value = optionsIndex[n];
						
						if (!value)
							return;
						
						if (ddCurrentOption)
							ddCurrentOption.text(options[value]);
						
						dd.trigger('onSwitchTo', [n]);

						if (noCallback != true)
							dd.trigger('dropdown_switchTo', [value, n, options[value]]);

						pos = n;
					})
					.bind('doLock', function(e) {
						isLocked = true;
					})
					.bind('doUnlock', function(e) {
						isLocked = false;
					})
					.css('cursor', 'pointer')
					.disableSelection();

			// Mode specific
				switch (mode)
				{
					case 'wide':

						var ddULLI = dd.find('ul li');

						dd
							.bind('init', function(e) {
								dd.trigger('switchTo', pos);
							})
							.bind('onSwitchTo', function(e, n) {
								ddULLI.removeClass('current_option');
								ddULLI.eq(n).addClass('current_option');
							});

						ddULLI.each(function() {
							var li = jQuery(this);
							
							li.click(function(e) {
								e.stopPropagation();
								dd.trigger('switchTo', li.index());
							});
						});
					
						break;
				
					case 'default':
					default:
					
						ddCurrentOption = dd.find('.currentOption');
						ddList = dd.find('ul');
						
						dd
							.bind('toggleList', function() {
								if (ddList.is(':visible'))
									dd.trigger('hideList');
								else
									dd.trigger('showList');
							})
							.bind('showList', function() {
								ddCurrentOption.addClass('currentOption_on');
								ddList.show();
							})
							.bind('hideList', function() {
								ddCurrentOption.removeClass('currentOption_on');
								ddList.hide();
							})
							.bind('init', function(e) {
								dd.trigger('switchTo', pos);
								dd.trigger('hideList');
							});
						
						ddCurrentOption
							.click(function(e) {
								e.stopPropagation();
								dd.trigger('toggleList');
							});
						
						dd.find('ul li').each(function() {
							var li = jQuery(this);
							
							li.click(function(e) {
								e.stopPropagation();
								dd.trigger('switchTo', li.index());
								dd.trigger('hideList');
							});
						});
						
						jQuery('body')
							.click(function(e) {
								dd.trigger('hideList');
							});
							
						break;
				}
						
			return dd;
		};

	////////////////////////////////////////////////////////////////////////////////////////////////
	// colorbox
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_colorbox = function() {
			
			////////////////////////////////////////////////////////////////////////////////////////
			// initialize
			////////////////////////////////////////////////////////////////////////////////////////

				var t = $(this), o = t.find('option'), fieldName = t.attr('name');
				t.hide();

				if (__degrade7)
				{
					t.show();
				
					o.each(function() {
						var x = $(this), tmp, name, code;

						if (x.val() == '')
							return;

						tmp = $.trim(x.text());
						code = tmp.match(/#[a-fA-F0-9]{6}/i)[0];
						name = tmp.split(' ')[0];
						x
							.text(name)
							.css('background-color', code);
					});
					
					return;
				}

				// Build colors array
					var colors = new Array();
					o.each(function() {
						var x = $(this), tmp, name, code;
						
						if (x.val() == '')
							return;

						tmp = $.trim(x.text());
						code = tmp.match(/#[a-fA-F0-9]{6}/i)[0];
						name = tmp.split(' ')[0];
						
						colors[x.val()] = new Array(code, name);
					});

				// Get current color
					var activeColor = t.val();

					if (activeColor == '')
						activeColor = 'none';
				
				// Build cb
					var tmp = '<span class="opt opt_none first">&nbsp;<strong>none</strong></span>';
					
					count = 1;
					
					for (i in colors)
					{
						tmp = tmp + '<span class="opt opt_' + i + (count % 4 == 0 ? ' first' : '') + '">&nbsp;<strong>' + i + '</strong></span>';

						count++;

						if (count % 4 == 0)
							tmp = tmp + '<br />';
					}
				
					var cb = $(
						'<div class="colorbox">' + 
							'<span class="opt opt_' + activeColor + ' opener">&nbsp;<strong>' + activeColor + '</strong></span>' +
							'<input type="hidden" name="' + fieldName + '" value="' + activeColor + '" />' +
							'<div class="panel">' + 
								'<div class="inner">' +
									tmp + 
								'</div>' +
							'</div>' +
						'</div>'
					);
					
					cb.insertAfter(t);
					
					t.remove();

			////////////////////////////////////////////////////////////////////////////////////////
			// configure
			////////////////////////////////////////////////////////////////////////////////////////
				
				// input
					var input = cb.find('input');

				// opener
					var opener = cb.find('.opener');
					opener
						.disableSelection()
						.click(function(e) {
							e.stopPropagation();
							cb.trigger('togglePanel');
						});
				
				// panel
					var panel = cb.find('.panel');
					panel
						.disableSelection()
						.click(function(e) {
							e.stopPropagation();
						})
						.css('position', 'absolute')
						.css('z-index', 1)
						.css('left', opener.position().left + opener.outerWidth() - panel.outerWidth())
						.css('top', opener.position().top + opener.outerHeight())
						.hide();

					panel.find('.inner')
						.css('z-index', 1);

					// opts
						var opts = panel.find('.opt');
						opts
							.click(function(e) {
								e.stopPropagation();
								var v = $.trim($(this).find('strong').text());
								cb
									.trigger('changeColor', [v])
									.trigger('hidePanel', true);
							});

				// cb
					cb
						.disableSelection()
						.bind('togglePanel', function(e) {
							if (panel.is(':visible'))
								cb.trigger('hidePanel');
							else
								cb.trigger('showPanel');
						})
						.bind('hidePanel', function(e, doSubmit) {
							opener.removeClass('opener_active');
							panel.fadeOut(100, function() {
								if (doSubmit)
									input.closest('form').trigger('submit');
							});
						})
						.bind('showPanel', function(e) {
							$('.colorbox .panel').trigger('hidePanel');
							opener.addClass('opener_active');
							panel
								.css('left', opener.position().left + opener.outerWidth() - panel.outerWidth())
								.css('top', opener.position().top + opener.outerHeight())
								.fadeIn(200);
						})
						.bind('changeColor', function(e, key, initial) {
							if (key == 'none')
								input.val('');
							else
								input.val(key);
							opener
								.removeClass('opt_' + activeColor)
								.addClass('opt_' + key)
								.find('strong')
									.text(key);
							activeColor = key;
						});
						
					cb.trigger('changeColor', [activeColor]);
					$('body').click(function(e) {
						cb.trigger('hidePanel');
					});
		};

	////////////////////////////////////////////////////////////////////////////////////////////////
	// xyz/n33
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.xyz = function(options) {
			var settings = jQuery.extend({
				selectorParent:		jQuery(this)
			}, options);
			return jQuery.xyz(settings);
		}

		jQuery.xyz = function(options) {
			// Settings
				var settings = jQuery.extend({
					selectorParent: 	null,
					hotspotSelector:	null,
					contentSelector:	null,
					follow:				true,
					xpos:				'right',
					ypos:				'bottom',
					xpad:				15,
					ypad:				15,
					bottomLeftClass:	'bottom_left',
					bottomRightClass:	'bottom_right',
					bottomCenterClass:	'bottom_center',
					topLeftClass:		'top_left',
					topRightClass:		'top_right',
					topCenterClass:		'top_center',
					delay:				450,
					cursor:				'help'
				}, options);

			settings.selectorParent.each(function() {
				// Vars
					var timeoutID, p = $(this), q = p.nextAll(settings.contentSelector), cy = settings.ypos, cx = settings.xpos;
					var _mobile = (navigator.userAgent.search(/(iOS|iPhone|iPad|Android)/) != -1);
				// Main
					function getLeft(offset)
					{
						switch (settings.xpos)
						{
							case 'center':
								cx = 'Center';
								if (offset <= q.outerWidth() + 5) {
									cx = 'Right';
									return Math.min(jQuery(window).width() - q.outerWidth(), offset + settings.xpad);
								}
								else if (offset >= jQuery(window).width() - q.outerWidth() - 5) {
									cx = 'Left';
									return Math.max(0, offset - q.outerWidth() - settings.xpad);
								}
								return Math.min(Math.max(0, offset - (q.outerWidth() / 2) + 1), jQuery(window).width() - q.outerWidth());
							case 'left':
								cx = 'Left';
								if (offset <= q.outerWidth() + 5) {
									cx = 'Right';
									return Math.min(jQuery(window).width() - q.outerWidth(), offset + settings.xpad);
								}
								return Math.max(0, offset - q.outerWidth() - settings.xpad);
							case 'right':
								cx = 'Right';
								if (offset >= jQuery(window).width() - q.outerWidth() - 5) {
									cx = 'Left';
									return Math.max(0, offset - q.outerWidth() - settings.xpad);
								}
								return Math.min(jQuery(window).width() - q.outerWidth(), offset + settings.xpad);
						}
								
						return offset;
					}
					
					function getTop(offset)
					{
						var n;
						switch (settings.ypos)
						{
							case 'top':
								n = offset - q.outerHeight() - settings.ypad;
								cy = 'top';
								if (n > 0)
									return n;
							case 'bottom':
								if (offset + q.outerHeight() >= jQuery(window).height() - settings.ypad) {
									cy = 'top';
									return offset - q.outerHeight() - settings.ypad;
								}
								cy = 'bottom';
								return Math.min(jQuery(window).height() - q.outerHeight(), offset + settings.ypad);
						}
						
						return offset;
					}
					
					var t;
					
					q.
						bind('turnon', function() {
							q.fadeIn(200);
						}).
						bind('turnoff', function() {
							q.hide();
						}).
						hide().
						css('position', 'fixed');
					p.
						bind('turnoff', function() {
							window.clearTimeout(timeoutID);
							q.trigger('turnoff');
						}).
						css('cursor', settings.cursor).
						mousemove(function(event) {
							if (settings.follow) {
								eval('t = settings.' + cy + cx + 'Class;');
								if (t)
									q.removeClass(t);
								q.css('top', getTop(event.clientY)).css('left', getLeft(event.clientX, true));
								eval('t = settings.' + cy + cx + 'Class;');
								q.addClass(t);
							}
						}).
						mouseenter(function(event) {
							if (settings.delay == 0)
								q.trigger('turnon');
							else
								timeoutID = window.setTimeout(function() {
									q.trigger('turnon');
								}, settings.delay);
						}).
						mouseleave(function() {
							window.clearTimeout(timeoutID);
							q.trigger('turnoff');
						});
						
					if (_mobile) {
						p.click(function(event) {
							if (q.is(':visible')) {
								window.clearTimeout(timeoutID);
								q.trigger('turnoff');
							}
						});
						q.click(function(event) {
							window.clearTimeout(timeoutID);
							q.trigger('turnoff');
						});
					}
			});
		}

	////////////////////////////////////////////////////////////////////////////////////////////////
	// formerize/n33
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_formerize = function() {
			// password fields
			jQuery(this)
				.find('input[type=password]')
					.each(function() {
						var e = jQuery(this);
						var x = jQuery(jQuery('<div>').append(e.clone()).remove().html().replace(/type="password"/i, 'type="text"').replace(/type=password/i, 'type=text'));
						if (e.attr('id') != '')
							x.attr('id', e.attr('id') + '_fakeformerizefield');
						if (e.attr('name') != '')
							x.attr('name', e.attr('name') + '_fakeformerizefield');
						x.addClass('blank').val(x.attr('title')).insertAfter(e);
						if (e.val() == '')
							e.hide();
						else
							x.hide();
						e.blur(function(event) {
							event.preventDefault();
							var e = jQuery(this);
							var x = e.parent().find('input[name=' + e.attr('name') + '_fakeformerizefield]');
							if (e.val() == '') {
								e.hide();
								x.show();
							}
						});
						x.focus(function(event) {
							event.preventDefault();
							var x = jQuery(this);
							var e = x.parent().find('input[name=' + x.attr('name').replace('_fakeformerizefield', '') + ']');
							x.hide();
							e.show().focus();
						});
						// just in case :P
						x.keypress(function(event) {
							event.preventDefault();
							x.val('');
						});
					});
			// text fields
			jQuery(this)
				.find('input[type=text],textarea')
					.each(function() {
						var e = jQuery(this);
						if (e.val() == '' || e.val() == e.attr('title')) {
							e.addClass('blank');
							e.val(e.attr('title'));
						}
					})
					.blur(function() {
						var e = jQuery(this);
						if (e.attr('name').match(/_fakeformerizefield$/))
							return;
						if (e.val() == '') {
							e.addClass('blank');
							e.val(e.attr('title'));
						}
					})
					.focus(function() {
						var e = jQuery(this);
						if (e.attr('name').match(/_fakeformerizefield$/))
							return;
						if (e.val() == e.attr('title')) {
							e.removeClass('blank');
							e.val('');
						}
					});
			// form events
			jQuery(this)
				// submit
				.submit(function() {
					jQuery(this)
						.find('input[type=text],textarea')
							.each(function(event) {
								var e = jQuery(this);
								if (e.attr('name').match(/_fakeformerizefield$/))
									e.attr('name', '');
								if (e.val() == e.attr('title')) {
									e.removeClass('blank');
									e.val('');
								}
							});
				})
				// reset
				.bind("reset", function(event) {
					event.preventDefault();
					// temporary: just set all SELECTs to their first options
					jQuery(this)
						.find('select')
							.val(jQuery('option:first').val());
					jQuery(this)
						.find('input,textarea')
							.each(function() {
								var e = jQuery(this);
								var x;
								e.removeClass('blank');
								switch (this.type) {
									case 'password':
										e.val(e.attr('defaultValue'));
										x = e.parent().find('input[name=' + e.attr('name') + '_fakeformerizefield]');
										if (e.val() == '') {
											e.hide();
											x.show();
										}
										else {
											e.show();
											x.hide();
										}
										break;
									case 'checkbox':
									case 'radio':
										e.attr('checked', e.attr('defaultValue'));
										break;
									case 'text':
									case 'textarea':
										e.val(e.attr('defaultValue'));
										if (e.val() == '') {
											e.addClass('blank');
											e.val(e.attr('title'));
										}
										break;
									default:
										e.val(e.attr('defaultValue'));
										break;
								}
							});
				});
				
			return jQuery(this);
		};

	////////////////////////////////////////////////////////////////////////////////////////////////
	// list
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_list = function() {
			var t = $(this), callout = t.find('.callout'), thumbs = t.find('.thumblist'), switcher = t.find('.switcher');

			// callout
				var calloutIsLocked = false;
			
				callout
					.hide()
					.bind('dismiss', function() {
						if (calloutIsLocked)
							return;
						calloutIsLocked = true;
						callout.fadeOut(300, function() {
							calloutIsLocked = false;
						});
					})
					.bind('reveal', function() {
						if (calloutIsLocked)
							return;
						calloutIsLocked = true;
						callout.fadeIn(300, function() {
							calloutIsLocked = false;
						});
					});
			
				callout.find('.closer')
					.disableSelection()
					.css('cursor', 'pointer')
					.click(function() {
						callout.trigger('dismiss');
					});
					
				t.find('.calloutOpener')
					.disableSelection()
					.css('cursor', 'pointer')
					.click(function() {
						if (callout.visible())
							callout.trigger('dismiss');
						else
							callout.trigger('reveal');
					});


			// switcher
				var switcherIsLocked = false;
				var switcherModes = new Array();
					switcherModes['bigThumbs'] = new Array('bigThumblist', 4);
					switcherModes['smallThumbs'] = new Array('smallThumblist', 5);
					switcherModes['wideThumbs'] = new Array('wideThumblist', 1);

				if (__degrade7)
					switcher.remove();
				else
				{
					/*
					if (_ls.length > 0)
						thumbs
							.each(function() {
								$(this).find('a').each(function() {
									var a = $(this), ah = a.attr('href');
									a.attr('href', ah + '-' + $._base64Encode(_ls));
								});
							});
					*/
				
					thumbs
						.bind('init1', function(e, mode) {
							switcher.find('li').each(function() {
								var t = $(this), cl = t.attr('class'); 
								if (t.attr('class') == mode)
								{
									t.attr('class', t.attr('class') + '_active');
									t.addClass('active');
								}
								else
								{
									t.attr('class', cl.replace(/_active/, ''));
									t.removeClass('active');
								}
							});
						})
						.bind('init2', function(e, mode) {
							var i = 0;
							thumbs.attr('class', 'thumblist ' + switcherModes[mode][0]);
							thumbs.find('.thumb').each(function() {
								var x = $(this);
								x.removeClass('first');
								if (i++ % switcherModes[mode][1] === 0)
									x.addClass('first');
							});
						});
						
					// Init
						p = af_getPref('4t', 'listSwitcher_status');

						if (!p || !switcherModes[p])
							p = 'wideThumbs';

						thumbs.trigger('init1', p);
						thumbs.trigger('init2', p);
					
					switcher.each(function() {

						switcher.find('li')
							.disableSelection()
							.click(function() {
								var t = $(this), c = t.attr('class'), p = af_getPref('4t', 'listSwitcher_status');
								if (!p)
									p = 'wideThumbs';
								if (switcherIsLocked || !switcherModes[c] || p == c)
									return;
								switcherIsLocked = true;
								thumbs.trigger('init1', c);
								thumbs.fadeTo(300, 0.01, function() {
									thumbs.trigger('init2', c);
									thumbs.fadeTo(300, 1, function() {
										switcherIsLocked = false;
									});
								});
								af_setPref('4t', 'listSwitcher_status', c);
							});
					});
				}
		
			// searchbar
				t.find('.searchbar').each(function() {
					var sb = $(this), t = sb.find('#type'), c = sb.find('#category'), f = sb.find('form'), search = sb.find('#search');
					var container = sb.find('.container'), shutter = sb.find('.shutter');

					var p = af_getPref('4t', 'listSearchbar_status');
					
					if (p == 'off')
						sb.addClass('searchbar_off');
					
					var searchSuggestions = new Array();
						searchSuggestions[0] = 'corporate glassy';
						searchSuggestions[1] = 'computers clean';
						searchSuggestions[2] = 'dark metallic';
						searchSuggestions[3] = 'bright distressed';
						searchSuggestions[4] = 'paper realistic';
						searchSuggestions[5] = 'jquery gallery';
						searchSuggestions[6] = 'music modern';

					search.attr('title', 'eg. ' + searchSuggestions[$.rand(0, searchSuggestions.length - 1)]);
					if (search.val().substring(0,3) == 'eg.')
						search.val('');
					f.ft_formerize();
					
					sb.find('a.search').attr('href', '').click(function(e) {
						e.preventDefault();
						f.trigger('submit');
					});
					
					f
						.submit(function(e) {
							var vt = t.val(), vc = c.val(), u = '/' + vt + '/' + (vc ? vc + '/' : ''), count = 0;
							f.attr('action', u);

							if (!__degrade7)
							{
								e.preventDefault();
								e.stopPropagation();
								f.find('input, select').each(function () {
									var tmp = $(this);
									if (tmp.val() == '' || tmp.val() == tmp.attr('title'))
									{
										tmp.attr('tmp-name', tmp.attr('name'));
										tmp.removeAttr('name');
									}
									else
									{
										if (tmp.attr('name'))
											count++;
									}
								});
								
								if (count === 0)
									window.location.href = u;
								else
									f.get(0).submit();
									
								f.find('input, select').each(function () {
									var tmp = $(this);
									if (tmp.attr('tmp-name'))
									{
										tmp.attr('name', tmp.attr('tmp-name'));
										tmp.removeAttr('tmp-name');
									}
								});
							}
						});
				
					shutter
						.click(function() {
						
							if (container.is(':visible'))
							{
								af_setPref('4t', 'listSearchbar_status', 'off');
								f.fadeOut(200);
								container.slideUp(250, function() {
									sb.toggleClass('searchbar_off');
								});
							}
							else
							{
								af_setPref('4t', 'listSearchbar_status', 'on');
								f.fadeIn(300);
								container.slideDown(250, function() {
									sb.toggleClass('searchbar_off');
								});
							}
						
						});
						
					sb.find('li').css('cursor', 'pointer');
					
					sb.find('select').change(function() {
						f.trigger('submit');
					});
				});

				t.find('.searchbar .color').each(function() {
					$(this).ft_colorbox();
				});

			// ipp
				t.find('.ipp select')
					.change(function() {
						af_setPref('4t', 'listIPP_count', $(this).val());
						var h = location.href, x = h.split('/'), y = new Array();
						for (i in x)
							if (!x[i].match(/^[0-9]+$/))
								y.push(x[i]);
						h = y.join('/');
						af_redirectAndReplace(h);
					});
					
		};

		if ($('#layout_list').exists())
			$('#layout_list').ft_list();

	////////////////////////////////////////////////////////////////////////////////////////////////
	// view
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_view = function() {
			var t = $(this);

			$('.liveDemo').show();
			
			if (__degrade9)
			{
				$('.seeLive').remove();
				
				$('.liveDemo a')
					.css('opacity', '0.25')
					.css('cursor', 'default')
					.attr('href', '#')
					.click(function(e) { return false; })
					.addClass('def')
					.attr('title', 'To see a LIVE demo of this design, please use at least Internet Explorer 10+, Chrome, Firefox, Safari, or Opera.');
			}

			// Preview
				(function () {
					var activeVariant, activeSlide, activeSlideName, isLocked = false, tmpimg = $('<img src="/site/images/spacer.gif" />');

					var variantViewer = t.find('.variantViewer');
					var thumbViewer = t.find('.thumbViewer');
					var summary = t.find('.summary');
					var preview = t.find('.preview');
						var preview_outer = preview.find('.image');
						var preview_img = preview.find('.image img');
						var preview_loader = preview.find('.image .loader');

					var tmp = window.location.hash.substring(1).split('-'), hv, hls;
					
					if (tmp.length > 0)
						hv = tmp[0];
					
					//if (tmp.length > 1)
					//	hls = tmp[1];

					function getXName(e,p) { return $.trim(e.attr('class').replace(/active/, '')).substring(p); }

					// Preview
						tmpimg
							.load(function() {
								if (tmpimg.attr('src').search(/spacer.gif$/) != -1)
									return true;

								preview_outer.css('height', 'auto');
							
								preview_img
									.stop(true, true)
									.attr('src', tmpimg.attr('src'))
									.fadeTo(0, 1);

								tmpimg
									.attr('src', '/site/images/spacer.gif');

								preview_loader
									.hide();
								
								activeSlide.status = 1;
								isLocked = false;
							});

						preview
							.bind('switchTo', function(e, name) {
								if (isLocked) return;

								if (!name || !activeVariant.slides[name])
									name = $.getFirstKey(activeVariant.slides);
									
								activeSlideName = name;
								activeSlide = activeVariant.slides[activeSlideName];
								
								thumbViewer.trigger('switchTo', activeSlideName);
								summary.text(activeSlide.title);
								
								src = activeSlide.previewURL;

								if (activeSlide.status == 1 || __degrade7)
								{
									preview_outer.css('height', 'auto');
									preview_img.attr('src', src);
								}
								else
								{
									isLocked = true;
									tmpimg.attr('src', src);
									preview_img.fadeTo(800, 0.65);
									preview_loader.fadeTo(500, 1);
								}
							});
							
						preview_img
							.disableSelection()
							.css('cursor', 'pointer')
							.click(function(e) {
								var i = $.getKeyPos(activeVariant.slides, activeSlideName) + 1;
								
								if (i > activeVariant.slides.length)
									i = 0;
									
								preview.trigger('switchTo', $.getNthKey(activeVariant.slides, i));
							});

					// Variant Viewer
						variantViewer
							.bind('switchTo', function(e, name) {
								if (isLocked) return;
									
								isLocked = true;
							
								if (!name || !ft_variants[name])
									name = $.getFirstKey(ft_variants);

								activeVariant = ft_variants[name];
								
								if (!activeSlideName)
									activeSlideName = $.getFirstKey(activeVariant.slides);
								
								activeSlide = activeVariant.slides[activeSlideName];

								// Change URL
									window.location.replace('#' + name + (hls ? '-' + hls : ''));

								// Change tab
									variantViewer.find('li').removeClass('active');
									variantViewer.find('.variantTab_' + name).addClass('active');
								
								// Change thumbViewer
									thumbViewer.find('ul').hide();
									thumbViewer.find('.variantThumbList_' + name).show();

								// Turn off locking
									isLocked = false;
								
								// Update preview
									preview.trigger('switchTo', activeSlideName);
									
								// Update variant-dependent links
									$('.takesVariantName').each(function() { var t = $(this); t.attr('href', t.attr('href').replace(/#.+/, '') + '#' + name); });
							});

						variantViewer.find('li a').click(function(e) {
							e.preventDefault();
							variantViewer.trigger('switchTo', $(this).attr('href').substring(1));
						});
						
					// Thumbviewer
						thumbViewer
							.bind('switchTo', function (e, name) {
								if (isLocked) return;

								thumbViewer.find('li').removeClass('active');
								thumbViewer.find('.slide_' + name).addClass('active');
							});
					
						thumbViewer.find('li')
							.disableSelection()
							.css('cursor', 'pointer')
							.click(function(e) {
								e.preventDefault();
								preview.trigger('switchTo',  getXName($(this), 6));
							});

					// Init
						variantViewer.trigger('switchTo', hv);
				})();

			// Related Products
				(function () {
					var relatedProducts = t.find('.relatedProducts');
					var viewer = relatedProducts.find('.viewer'), thumblist = relatedProducts.find('.thumblist');
					var next = relatedProducts.find('.next'), previous = relatedProducts.find('.previous');
					var pos = 0, d = viewer.width() + 5, count = Math.round(thumblist.width() / d);
					var isLocked = false;

					relatedProducts
						.bind('checkPos', function() {
							if (pos >= count - 1)
								next.trigger('disable');
							else
								next.trigger('enable');

							if (pos <= 0)
								previous.trigger('disable');
							else
								previous.trigger('enable');
						})
						.bind('next', function() {
							if (isLocked == false && pos < count - 1)
							{
								isLocked = true;
								pos++;
								thumblist.animate({left: -1 * (pos * d)}, 'slow', 'swing', function() {
									relatedProducts.trigger('checkPos');
									isLocked = false;
								});
							}
						})
						.bind('previous', function() {
							if (isLocked == false && pos > 0)
							{
								isLocked = true;
								pos--;
								thumblist.animate({left: -1 * (pos * d)}, 'slow', 'swing', function() {
									relatedProducts.trigger('checkPos');
									isLocked = false;
								});
							}
						});
					
					next
						.disableSelection()
						.bind('disable', function() {
							next.addClass('disabled');
						})
						.bind('enable', function() {
							next.removeClass('disabled');
						})
						.click(function() {
							relatedProducts.trigger('next');
						});
					
					previous
						.disableSelection()
						.bind('disable', function() {
							previous.addClass('disabled');
						})
						.bind('enable', function() {
							previous.removeClass('disabled');
						})
						.click(function() {
							relatedProducts.trigger('previous');
						});
						
					relatedProducts.trigger('checkPos');
				})();
		};

		if ($('#layout_view').exists())
			$('#layout_view').ft_view();

	////////////////////////////////////////////////////////////////////////////////////////////////
	// liveDemo
	////////////////////////////////////////////////////////////////////////////////////////////////

		jQuery.fn.ft_liveoffsitedemo = function() {
			var _shutter = $('.shutter');
			var _demobar = $('.demobar');
			var _main = $('.main');
			var _iframe = $('<iframe src="" name="ndemoframe" class="demoframe"></iframe>').appendTo(_main);
			var _variants = $('.variants');

			var _controls = $('.controls');
			var _slides = $('.slides');
			var _slideSelectors = { };
			var _activeSlideSelector;
			var isResponsive = _slides.hasClass('slides_responsive');
			var activeVariant, activeSlide;

			var shutterLocked = false;
			var pad = 20;
			var w = $(window), wh = $(window).height();
			var URLs = new Array();

			if (__degrade8)
			{
				_main.remove();
				return;
			}

			if (__mobile)
				pad = 0;
			else
				_shutter.show();

			// iframe
				_iframe
					.bind('switchTo', function(e, v) {
						frames.ndemoframe.location.replace(v);
					})
					.bind('fixFocus', function() {
						_iframe.focus();
						//_iframe.contents().find('html').focus();
					})
					.load(function() {
						_iframe.trigger('fixFocus');
					});

			// variants
				_variants.find('a').each(function() {
					var t = $(this);
					URLs[t.attr('href').substring(1)] = t.attr('title');
					t.attr('title', '');
				});
				
				_variants
					.bind('switchTo', function(e, name) {
						// Change URL
							window.location.replace('#' + name);

						// Change tab
							_variants.find('li').removeClass('active');
							_variants.find('.variantTab_' + name).addClass('active');

						// Change IFRAME
							_iframe.trigger('switchTo', URLs[name]);
							_iframe.trigger('fixFocus');

						// Change slides
							_slides.trigger('initVariant', name);
					});

				_variants.find('li a').click(function(e) {
					e.preventDefault();
					_variants.trigger('switchTo', $(this).attr('href').substring(1));
				});

			// shutter
				_shutter
					.bind('expand', function() {
						shutterLocked = true;
						_demobar.show();
						_iframe.animate({
							height: wh - _demobar.height() - pad
						}, 0, 'swing', function() {
							shutterLocked = false;
							_shutter.removeClass('shutter_off');
							_main.css('z-index', 1);
						});
					})
					.bind('collapse', function() {
						shutterLocked = true;
						_main.css('z-index', 100);
						_iframe.animate({
							height: wh - pad
						}, 0, 'swing', function() {
							shutterLocked = false;
							_demobar.hide();
							_shutter.addClass('shutter_off');
						});
					})
					.bind('click', function() {
						if (shutterLocked)
							return true;
						_shutter.trigger(_demobar.visible() ? 'collapse' : 'expand');
						_iframe.trigger('fixFocus');
					});

			// slideSelector

				// dropdowns
					_slides.find('select').each(function() {
						var id, x, t = $(this);
						id = t.attr('id').split('_')[1];
						
						x = t.ft_dropdown('wide');

						$('<span class="downarrow"></span>')
							.appendTo(x)
							.click(function(e) {
								e.stopPropagation();
								x.trigger('toggleList');
							});
						
						x
							.bind('dropdown_switchTo', function(e, v, pos, k) {
								
								for (var i in _slideSelectors)
									_slideSelectors[i].trigger('switchTo', [pos, true]);
							
								activeSlide = k;
							
								if (activeVariant == id)
								{
									var tmp = v.split(',');
									
									if (k == 'Mobile' || k == 'Tablet' || k == 'Desktop')
									{
										switch (k)
										{
											case 'Mobile':
												useWidth = 400;
												break;
												
											case 'Tablet':
												useWidth = 1050;
												break;

											default:
											case 'Desktop':
												useWidth = w.width();
												break;
										}
										
										useWidth = Math.min(useWidth, w.width());
										
										if (_iframe.width() != useWidth)
										{
											x.trigger('doLock');
											_iframe.fadeTo(400, 0.001, function() {
												_iframe
													.bind('load.tmp', function() {
														_iframe.fadeTo(400, 1, function() {
															x.trigger('doUnlock');
															_iframe.unbind('load.tmp');
														});
													});

												_iframe
													.width(useWidth)
													.trigger('switchTo', URLs[activeVariant]);
											});
										}
										else
										{
											_iframe
												.trigger('switchTo', URLs[activeVariant])
												.trigger('fixFocus');
										}
									}
									else
									{
										_iframe
											.trigger('switchTo', URLs[activeVariant])
											.trigger('fixFocus');
									}
								}
							})
							.hide();

						_slideSelectors[id] = x;
					});

				// init
					_slides
						.bind('switchVariant', function (e, name) {
							if (_activeSlideSelector)
								_activeSlideSelector.hide();
							
							activeVariant = name;
							_activeSlideSelector = _slideSelectors[activeVariant];
							_activeSlideSelector.show();
						})
						.bind('initVariant', function (e, name) {
							if (!name || !_slideSelectors[name])
								name = $.getFirstKey(_slideSelectors)						
							
							_slides.trigger('switchVariant', name);

							for (var x in _slideSelectors)
								_slideSelectors[x].trigger('init');
						})
						.show();

			// init
				_iframe
					.css('display', 'block')
					.show();

				w.resize(function(e) { var h = wh - _demobar.height() - pad; _iframe.height(h); if (__mobile) _main.height(h); });
				w.trigger('resize');
				_demobar.disableSelection();
				_shutter.disableSelection();
				_iframe.disableSelection();

				_variants.trigger('switchTo', window.location.hash.substring(1));
		}

		jQuery.fn.ft_livedemo = function() {
			var _shutter = $('.shutter');
			var _demobar = $('.demobar');
			var _main = $('.main');
			var _iframe = $('<iframe src="" name="ndemoframe" class="demoframe"></iframe>').appendTo(_main);
			var _variants = $('.variants');
			var _controls = $('.controls');
			var _slides = $('.slides');
			var _slideSelectors = { };
			var _slideSelectorPrev = $('.slides .prevSlide');
			var _slideSelectorNext = $('.slides .nextSlide');
			var _activeSlideSelector;
			var isResponsive = _slides.hasClass('slides_responsive');
			var activeVariant, activeSlide;
			var shutterLocked = false;
			var pad = 20;
			var useWidth = false;
			var w = $(window), wh = $(window).height();

			if (__degrade8)
			{
				_main.remove();
				return;
			}

			if (__mobile)
			{
				_shutter.remove();
				_main
					.css('position', 'relative')
					.css('top', _demobar.height() + 'px');
				pad = 0;
			}

			if (!isResponsive)
				_controls.css('width', '320px');

			// iframe
				_iframe
					.bind('reload', function() {
						frames.ndemoframe.location.reload();
					})
					.bind('switchTo', function(e, v) {
						frames.ndemoframe.location.replace(v);
					})
					.bind('fixFocus', function() {
						_iframe.focus();
						_iframe.contents().find('html').focus();
					})
					.load(function() {
						_iframe.trigger('fixFocus');
					});

			// variants
				_variants
					.bind('switchTo', function(e, name) {
						if (!name || !_slideSelectors[name])
							name = $.getFirstKey(_slideSelectors);
					
						// Change URL
							window.location.replace('#' + name);

						// Change tab
							_variants.find('li').removeClass('active');
							_variants.find('.variantTab_' + name).addClass('active');

						// Change slides
							_slides.trigger('initVariant', name);
					});

				_variants.find('li a').click(function(e) {
					e.preventDefault();
					_variants.trigger('switchTo', $(this).attr('href').substring(1));
				});

			// slideSelector

				// dropdowns
					_slides.find('select').each(function() {
						var id, x, t = $(this);
						id = t.attr('id').split('_')[1];
						
						x = t.ft_dropdown(isResponsive ? 'wide' : 'default');

						$('<span class="downarrow"></span>')
							.appendTo(x)
							.click(function(e) {
								e.stopPropagation();
								x.trigger('toggleList');
							});
						
						x
							.bind('dropdown_switchTo', function(e, v, pos, k) {
								for (var i in _slideSelectors)
									_slideSelectors[i].trigger('switchTo', [pos, true]);
							
								activeSlide = k;
							
								if (activeVariant == id)
								{
									var tmp = v.split(',');
									
									if (k == 'Mobile' || k == 'Tablet' || k == 'Desktop')
									{
										switch (k)
										{
											case 'Mobile':
												useWidth = 400;
												break;
												
											case 'Tablet':
												useWidth = 1050;
												break;

											default:
											case 'Desktop':
												useWidth = w.width();
												break;
										}
										
										useWidth = Math.min(useWidth, w.width());
										
										if (_iframe.width() != useWidth)
										{
											x.trigger('doLock');
											_iframe.fadeTo(400, 0.001, function() {
												_iframe
													.bind('load.tmp', function() {
														_iframe.fadeTo(400, 1, function() {
															x.trigger('doUnlock');
															_iframe.unbind('load.tmp');
														});
													});

												_iframe
													.width(useWidth)
													.trigger('switchTo', '/support/demos/' + tmp[0].substr(20));
											});
										}
										else
										{
											_iframe
												.trigger('switchTo', '/support/demos/' + tmp[0].substr(20))
												.trigger('fixFocus');
										}
									}
									else
									{
										_iframe
											.trigger('switchTo', '/support/demos/' + tmp[0].substr(20))
											.trigger('fixFocus');
									}
								}
							})
							.hide();

						_slideSelectors[id] = x;
					});

				// nav buttons
					if (isResponsive)
					{
						_slideSelectorPrev.hide();
						_slideSelectorNext.hide();
					}
					else
					{
						_slideSelectorPrev
							.click(function() { _activeSlideSelector.trigger('switchPrev'); });
						_slideSelectorNext
							.click(function() { _activeSlideSelector.trigger('switchNext'); });
					}
			
				// init
					_slides
						.bind('switchVariant', function (e, name) {
							if (_activeSlideSelector)
								_activeSlideSelector.hide();
							
							activeVariant = name;
							_activeSlideSelector = _slideSelectors[activeVariant];
							_activeSlideSelector.show();
						})
						.bind('initVariant', function (e, name) {
							if (!name || !_slideSelectors[name])
								name = $.getFirstKey(_slideSelectors)						
							
							_slides.trigger('switchVariant', name);

							for (var x in _slideSelectors)
								_slideSelectors[x].trigger('init');
						})
						.show();

			// shutter
				_shutter
					.bind('expand', function() {
						shutterLocked = true;
						_demobar.show();
						_iframe.animate({
							height: wh - _demobar.height() - pad
						}, 0, 'swing', function() {
							shutterLocked = false;
							_shutter.removeClass('shutter_off');
							_main.css('z-index', 1);
							if (activeSlide == 'Mobile')
								_iframe.trigger('reload');
						});
					})
					.bind('collapse', function() {
						shutterLocked = true;
						_main.css('z-index', 100);
						_iframe.animate({
							height: wh - pad
						}, 0, 'swing', function() {
							shutterLocked = false;
							_demobar.hide();
							_shutter.addClass('shutter_off');
							if (activeSlide == 'Mobile')
								_iframe.trigger('reload');
						});
					})
					.bind('click', function() {
						if (shutterLocked)
							return true;
						_shutter.trigger(_demobar.visible() ? 'collapse' : 'expand');
						_iframe.trigger('fixFocus');
					});

			// init
				_iframe
					.css('display', 'block')
					.show();

				w
					.resize(function(e) {
						var h = w.height() - _demobar.height() - pad;
						
						_iframe
							.height(h);
						
						if (__mobile)
							_main.height(h);
					})
					.trigger('resize');

				_demobar.disableSelection();
				_shutter.disableSelection();
				_iframe.disableSelection();

				_variants.trigger('switchTo', window.location.hash.substring(1));
		};
		
		var tmp = $('#livedemo');
		
		if (tmp.exists())
			if (tmp.hasClass('offsite'))
				$('#livedemo').ft_liveoffsitedemo();
			else
				$('#livedemo').ft_livedemo();

	////////////////////////////////////////////////////////////////////////////////////////////////
	// social
	////////////////////////////////////////////////////////////////////////////////////////////////

		if (!__degrade7)
		{
			// Facebook
				(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
			// Google Plus
				(function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })();
			// Twitter
				$('head').append('<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>');
		}
		
	////////////////////////////////////////////////////////////////////////////////////////////////
	// misc
	////////////////////////////////////////////////////////////////////////////////////////////////

		// ie7 fix
			if (__degrade7)
				$('#layout_cart .rootCommand table').hide().show();

		// thumbs
			$('.thumb').each(function() {
				var t = $(this), variants = t.find('.variants ul li'), thumbLink = t.find('.link'), thumbImage = t.find('.image a img');
				
				variants
					.css('cursor', 'pointer')
					.mouseenter(function() {

						var t = $(this), newSRC = '/site/product_images/thumbnails/' + t.find('img').attr('alt') + '.jpg';

						if (thumbImage.attr('src') == newSRC)
							return false;

						variants.removeClass('active');

						t.addClass('active');

						thumbImage
							.stop(true)
							.fadeTo('fast', 0.1, function() {
								thumbImage
									.attr('src', newSRC)
									.fadeTo('fast', 1.0, function() {
										thumbLink.attr('href', t.find('a').attr('href'));
									});
							});
					});
			});

	////////////////////////////////////////////////////////////////////////////////////////////////
	// labels
	////////////////////////////////////////////////////////////////////////////////////////////////

		if (!__degrade6)
		{
			var settings = {
				contentSelector: '.xyzlabel',
				follow: true,
				xpos: 'center',
				ypos: 'top',
				xpad: 0,
				ypad: 25,
				delay: 150,
				bottomLeftClass: 'xyzlabel_bottom_left',
				bottomRightClass: 'xyzlabel_bottom_right',
				bottomCenterClass: 'xyzlabel_bottom_center',
				topLeftClass: 'xyzlabel_top_left',
				topRightClass: 'xyzlabel_top_right',
				topCenterClass: 'xyzlabel_top_center'
			};
		
			$('.def, .defClick').each(function() {
				var t = $(this);
				$('<span class="xyzlabel">' + t.attr('title') + '<span class="arrow"></span></span>').insertAfter(t);
				t.attr('title', '');
			});
			
			$('.def').xyz(settings);
			$('.defClick').xyz($.extend(settings, { cursor: 'pointer', delay: 400 }));

			$('.cdef').xyz(settings);
		}

});